from flask import (Blueprint, request, session)
from flaskr.server.SheetsServer import *
import pandas as pd

bp = Blueprint('setType', __name__, url_prefix='/setType')

@bp.route('', methods = ['POST'])
def set_type():
    sheet_name = request.json.get('sheetName')
    field_name = request.json.get('field')
    type = request.json.get('type')

    sheet = get_sheet(sheet_name)
    df = get_dataframe(sheet)

    if type == 'datetime':
        df[field_name] = pd.to_datetime(df[field_name])

    elif type == 'object':
        df[field_name] = df[field_name].astype('category')

    elif type == 'float':
        df[field_name] = df[field_name].astype('float')

    elif type == 'int':
        df[field_name] = df[field_name].astype('int')





